import Vue from 'vue'
import App from './App.vue'
import router from './router'

import axios from 'axios'
import VueAxios from 'vue-axios'

import VueRouter from 'vue-router'

import VueScroller from 'vue-scroller'
 

import waterfall from 'vue-waterfall2'
Vue.use(waterfall)

import 'lib-flexible/flexible'


import {
  Tabbar,
  TabbarItem,
  Search,
  Tab,
  Tabs,
  Swipe,
  SwipeItem,
  Lazyload,
  NavBar,
  Icon,
  Toast,
  Sidebar,
  SidebarItem,
  List,
  Cell,
  CellGroup,
  PullRefresh,
  Uploader,
  Empty,
  Form,
  Field,
  Button,
  Popup,
  Dialog,
  DropdownMenu,
  DropdownItem,
  IndexBar,
  IndexAnchor,
  Rate,
  Collapse,
  CollapseItem,
  Progress,
  ShareSheet
} from 'vant';



//添加一个axios请求之前拦截器
axios.interceptors.request.use(config => {

  //启动加载提示
  Toast.loading({
    message: '加载中...',
    //禁止穿透点击
    forbidClick: true,
    loadingType: 'spinner',
    //不会自动关闭提示
    duration: 0
  })



  return config;
}, err => {
  
  //关闭加载提示
  Toast.clear();
  return Promise.reject(err);
})

//添加一个响应之前拦截器
axios.interceptors.response.use(res => {
  //res: 服务器响应数据
  // 

  //关闭加载提示
  Toast.clear();

  return res;
}, err => {
  

  //关闭加载提示
  Toast.clear();

  return Project.reject(err);
})

Vue.use(VueAxios, axios)



Vue
  .use(Tabbar)
  .use(TabbarItem)
  .use(Search)
  .use(Tab)
  .use(Tabs)
  .use(Swipe)
  .use(SwipeItem)
  .use(Lazyload)
  .use(NavBar)
  .use(Icon)
  .use(Toast)
  .use(Sidebar)
  .use(SidebarItem)
  .use(List)
  .use(Cell)
  .use(CellGroup)
  .use(PullRefresh)
  .use(Uploader)
  .use(Empty)
  .use(Form)
  .use(Field)
  .use(Button)
  .use(Popup)
  .use(Dialog)
  .use(DropdownMenu)
  .use(DropdownItem)
  .use(IndexBar)
  .use(IndexAnchor)
  .use(Rate)
  .use(Collapse)
  .use(CollapseItem)
  .use(Progress)
  .use(ShareSheet)
  .use(Lazyload, {
    lazyComponent: true,
  })



Vue.use(VueScroller)


//点击相同路由报错的解决方法, 捕获错误
let originPush = VueRouter.prototype.push;

//重新VueRouter的原型的push方法
VueRouter.prototype.push = function (location) {
  //location: 目标路由的信息
  // 

  originPush.call(this, location, () => { }, (err) => {
    // 
  });
}


Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
